package com.ruoyi.web.controller.front;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.HaveFun;
import com.ruoyi.system.service.IHaveFunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/haveFun")
public class HaveFunController extends BaseController {

    @Autowired
    private IHaveFunService haveFunService;

    @PostMapping("/save")
    public AjaxResult save(@RequestBody HaveFun haveFun) {
        return haveFunService.saveHaveFun(haveFun);
    }

    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Long id) {
        return AjaxResult.success(haveFunService.getHaveFunById(id));
    }

    @GetMapping("/list")
    public AjaxResult list(HaveFun haveFun,
                           @RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "10") Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<HaveFun> list = haveFunService.getHaveFunList(haveFun);
        return AjaxResult.success(new PageInfo<>(list));
    }

    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids) {
        return toAjax(haveFunService.deleteHaveFunByIds(ids));
    }
}
